<template>
	<view class="box bg-f7">
		<view class="index-bg">
			<image :src='BASE_URL + "/uploads/20250801/dce5c06c50b04d981d1e2843da64896a.png"' mode="widthFix"></image>

		</view>
		<view class="z-1">
			<u-navbar :titleStyle='{"color":"#Fff"}' leftIconColor='#000' title="  " bgColor="transparent"
				@rightClick="rightClick" :autoBack="true" :fixed="false"> </u-navbar>
			<view class="index-text color-0 fw-b flex-column">
				<text class="fs-40">{{userInfo.admin_name}}社区</text>
				<text class="fs-46">分诊预约</text>
			</view>
			<view class="padding-l-r-20">
				<view>
					<view
						class="nav-list bg-white padding-l-r-30 margin-b-20 align-items-center justifyContent-spaceBetween">
						<view class="fs-30 fw-b color-333" @click="getNav(item,index)" v-for="(item,index) in navList"
							:key="item.id" :class="{active:navIndex==index}">{{item.name}}</view>
					</view>
					<view v-if="navIndex">
						<healthList :list='list' ref="healthList" :typeList='typeList' @getType="getType"
							@goDetails="goDetails"></healthList>
					</view>
					<view v-else>
						<medicalList :list='list' ref="medicalList" :typeList='typeList' @goDetails="goDetails"
							@getType="getType" ></medicalList>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import medicalList from "./components/medicalList.vue";
	import healthList from "./components/healthList.vue";
	import $baseUrl from "@/config/index.js"
	const BASE_URL = $baseUrl.baseUrl
	import {
		publicityList,
		cateList,
		publicitySign
	} from "@/api/culturalPropaganda"
	export default {
		components: {
			medicalList,
			healthList
		},
		data() {

			return {
				navList: [],
				navBarHeight: 0,
				navIndex: 0,
				 
				typeList: [],
				BASE_URL,
				list: [],
				typeName: '',
				page: 1,
                isMore:false,
				userInfo:{}
			}
		},
		onLoad() {
			this.getCate()
			this.userInfo = uni.getStorageSync('userInfo')
		},
        //上拉加载函数
        onReachBottom() {
            if (this.isMore) {
                setTimeout(() => {
                    this.getList()
                }, 100)
            } else {
                uni.showToast({
                    title: '暂无更多',
                    icon: 'none'
                })
            }

        },
        onPullDownRefresh() {
            //刷新初始化数据
            this.initList()
            //关闭刷新动画
            setTimeout(function() {
                uni.stopPullDownRefresh()
            }, 1000)
        },
		methods: {
			getCate() {
				cateList({
					type: 2
				}).then(res => {
					if (res.code == 1) {
						this.navList = res.data
						this.typeList = res.data[0].list
                        this.typeName=this.typeList[0].name
                        console.log( this.typeList[0])
						this.initList()
					}
				})
			},
			initList() {
				this.page = 1
				this.list = []
				this.getList()
			},
			// 报名
			sign(item) {
				publicitySign({publicity_id:item.id}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '报名成功',
							icon: 'none'
						})
						this.initList()
					}
				})
			},
			getList( ) {
				let params = {
					page: this.page,
					limit: 10,
					cate_pid_name: this.typeName
				}
				publicityList(params).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data)
                        if (res.data && res.data.length > 9) {
                            this.isMore = true
                            this.page++
                        } else {
                            this.isMore = false
                        }
					}else {
                        uni.showToast({
                            title: res.msg,
                            icon: 'none'
                        })
                    }
				})
			},
			getNav(item, index) {
				this.navIndex = index;
				this.typeList = item.list
				if (index) {
					this.$nextTick(() => {
						this.$refs.healthList.initType()
					});

				} else {
					this.$nextTick(() => {
						this.$refs.medicalList.initType()
					});
				}
				 this.typeName = item.list[0].name
				this.initList()
			},
			getType(item) {
                console.log(item)
				this.typeName = item.name
				this.initList()
			},
			goDetails(item, index) {
				if (this.navIndex) {
					uni.navigateTo({
						url: '/pageA/culturalPropaganda/healthDetails?id=' + item.id
					})
				} else {
					uni.navigateTo({
						url: '/pageA/culturalPropaganda/scienceDetails?id=' + item.id
					})
				}
			},
			rightClick() {
				uni.navigateBack()
			},
		},
	}
</script>

<style scoped lang="scss">
	.index-text {
		padding: 55rpx;
	}

	.nav-list {
		height: 100rpx;
		line-height: 100rpx;
		border-radius: 50rpx;

		.active {
			position: relative;
			color: #43ABC4;

			&::after {
				content: '';
				position: absolute;
				bottom: 10rpx;
				left: 50%;
				width: 30rpx;
				height: 6rpx;
				background: #43ABC4;
				border-radius: 3rpx;
				transform: translateX(-50%);

			}
		}
	}
</style>
